package cn.wolfcode.wolf2w.elasticsearch.service.impl;

import cn.wolfcode.wolf2w.elasticsearch.domain.DestinationEs;
import cn.wolfcode.wolf2w.elasticsearch.repository.DestinationESRepository;
import cn.wolfcode.wolf2w.elasticsearch.service.IDestinationESService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DestinationESServiceImpl implements IDestinationESService {
    @Autowired
    private DestinationESRepository destinationESRepository;

    @Autowired
    private ElasticsearchTemplate template;

    @Override
    public void save(DestinationEs destinationES) {
    destinationESRepository.save(destinationES);
    }

    @Override
    public void update(DestinationEs destinationES) {
    destinationESRepository.save(destinationES);
    }

    @Override
    public void delete(String id) {
    destinationESRepository.deleteById(id);
    }

    @Override
    public DestinationEs get(String id) {
        return destinationESRepository.findById(id).orElse(null);
    }

    @Override
    public List<DestinationEs> listAll() {
        Iterable<DestinationEs> iterable = destinationESRepository.findAll();
        ArrayList<DestinationEs> list = new ArrayList<>();
        iterable.forEach(a -> list.add(a));
        return list;
    }
}